package com.supermarket.seefood51.login.model

import android.content.Context
import com.example.http.HttpManager
import com.example.http.listener.HttpOnNextListener
import com.supermarket.seefood51.api.LoginApi
import com.supermarket.seefood51.base.BaseModel
import com.supermarket.seefood51.entity.UserEntity
import com.supermarket.seefood51.linstener.OnLoadRequestListener
import com.trello.rxlifecycle.components.support.RxAppCompatActivity

class LoginModelImpl : LoginModel {


    override fun login(context: Context, name: String, pwd: String,deviceId:String, listener: OnLoadRequestListener<UserEntity>) {

       val loginApi = LoginApi(context as RxAppCompatActivity, name, pwd,deviceId , object :
               HttpOnNextListener<UserEntity>() {
           override fun onNext(t: UserEntity?) {
               listener.onSuccess(t)
           }

           override fun onError(e: Throwable?) {
               listener.onFail(e)
           }
       })
        //采用已经封装完毕的RX+Retrofit框架
        HttpManager.getInstance().doHttpDeal(loginApi)
    }

}